/*
 * @Date: 2023-08-20 19:32:51
 * @LastEditors: Wangjun
 * @LastEditTime: 2023-08-29 16:46:05
 * @FilePath: \nodex\nodemath\op_sub.go
 * @Description:
 */
package nodemath

import (
	"gitee.com/hnxr_1/nodex"
)

func init() {
	nodex.Reister(new(SUB))
}

type SUB struct {
	nodex.Node
	X1 nodex.Double `remark:"输入1"`
	X2 nodex.Double `remark:"输入2"`
	Y  nodex.Double `remark:"输出Y,,out"`
}

func (m *SUB) GetModelID() int {
	return nodex.ModMath
}

/**
 * @description:
 * @return {*}
 */
func (m *SUB) GetName() string {
	return "SUB"
}
func (m *SUB) RegData() []byte {
	return nodex.MakeRegData(m, "减法运算", m.GetName(), "")
}

func (m *SUB) Calc() (err error) {
	if m.EnQ {
		if *m.X1.Bad || *m.X2.Bad {
			m.Bad = true
			return //不计算
		}
	}

	m.Bad = false
	m.Y.Value = m.X1.Value - m.X2.Value
	return
}
